<?php
define('IN_YCTOOL', true);//定义该文件合法性
require('../../../../config.php');
require(DIR_COMM . 'func.class.php');
require(DIR_COMM . 'db.class.php');
require(DIR_CTRL . 'user.class.php');
require(DIR_COMM . 'common.php');
$user = new user();
$pre = '../../../../';
$user->isLogin($pre);
$userid		= $user->userinfo['userid'];
$action		= isset($_POST['action']) ? $_POST['action'] : "";
$uidpathusr	= 'userdata/' . func::getFilePath($userid);
$data		= $uidpathusr . 'pic/';
if (!file_exists($pre . $data))
{
    func::getFilePath2($userid, $pre . 'userdata/', 'pic');
}
?>
<html><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><title>插入图片</title>
<?php
if($_POST)
{
    require("FCKphoto.php");
    echo '<script language="javascript">window.parent.geturl("../../../'.$userpic.'");</script>';
    exit;
}
?>
<script src="common/fck_dialog_common.js" type="text/javascript"></script>
<script src="fck_image/fck_image_php.js" type="text/javascript"></script>
<script language="javascript">
<!--
domain = '';
var flagk=0;
function checkname(sid)
{
	var filename1=document.getElementById(sid).value;
	var len=filename1.length;
	var filename2=filename1.substr((len-4),4);
	if(filename1!="")
	{
		if((filename2==".jpg")||(filename2==".png")||(filename2==".bmp")||(filename2==".gif")||(filename2==".JPG")||(filename2==".PNG")||(filename2==".BMP")||(filename2==".GIF"))
   			{		
   				return true;
			}
		else
			{
				alert("不合适的图片格式");
				return false;
			}
	}
	else
	{
	alert("你未选择任何照片,请选择后上传");
		return false;
	}
}

var img=null;
function s(fname)
{
	if(!document.all){ return false;}
	flagk=0;
	if(img)img.removeNode(true);
	img=document.createElement("img");
	img.style.position="absolute";
	img.style.display="none";
	img.style.visibility="hidden";
	img.attachEvent("onreadystatechange",orsc);
	document.body.insertAdjacentElement("beforeend",img);
	img.src=document.getElementById(fname).value;
}
function oe()
{
	alert("指定路径图片失败!");
	flagk++;
}
function orsc()
{
	if(img.readyState!="complete")
	{
	}
	else if(img.fileSize>512000)
	{
		alert("图片最大500KB");
		flagk++;
	}
}

function checkfile(fileid)
{	
	var ele=document.getElementById(fileid);
	var len=ele.length;
	if(len!=0)
	{	
		if(checkname(fileid)&&(flagk==0))
			{
				return true;
			}
		else
			{
				
				return false;
			}	
		
	}
}

function formatonlinpic()
{
var picobj=document.getElementsByName("onlinepic");
var picnum=picobj.length;
	for(var i=0;i<picnum;i++)
	{
		if(picobj[i].width>200)
		{
			picobj[i].width=200;
		}
		if(picobj[i].height>200)
		{
			picobj[i].height=200;
		}
	}

}

function uping()

{
	if(checkfile("spPhotoFile0"))
	{
		showDiv("addsever",1);
		showDiv("addseverlink",0);
		showDiv("addlocal",1);
		showDiv("addlocallink",0);
		showDiv("imgaddsever",0);
		showDiv("imgaddlocal",0); 
		showDiv("showing",1);
		formatonlinpic();
		try{
			document.form1.submit();
		}catch (e){
			showDiv("addsever",0);
			showDiv("addseverlink",1);
			showDiv("addlocal",1);
			showDiv("addlocallink",0);
			showDiv("imgaddsever",0);
			showDiv("imgaddlocal",1); 
			showDiv("showing",0);
			alert("您指定的图片不存在，请检查后重试。");
		}
	}
	return false;
}

function showDiv(divid,status)
{
	var curDiv = document.getElementById(divid);
	if(curDiv){
		if(status==0)
			curDiv.style.display = "none";
		else
			curDiv.style.display = "";
	}
}

function chgdiv(flag)
{
	if(flag==1)
	{
		showDiv("addsever",1);
		showDiv("addseverlink",0);
		showDiv("addlocal",0);
		showDiv("addlocallink",1);
		
		showDiv("imgaddsever",1);
		showDiv("imgaddlocal",0);
		
	}
	else if(flag==0)
	{
		showDiv("addsever",0);
		showDiv("addseverlink",1);
		showDiv("addlocal",1);
		showDiv("addlocallink",0);
		
		showDiv("imgaddsever",0);
		showDiv("imgaddlocal",1);
	}
}

var MaxHeight = 150;
var MaxWidth = 110;

function DownImage(ImgD)
{ 
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0){ 
		var rate = (MaxWidth/image.width < MaxHeight/image.height)?MaxWidth/image.width:MaxHeight/image.height;
		if(rate <= 1){			
			ImgD.width = image.width*rate;
			ImgD.height =image.height*rate;
		}else{
			ImgD.width = image.width;
			ImgD.height =image.height;
		}
		
    } 
}

function AddLink(oForm) 
{
if(document.getElementById("url").value=="http://")
	{
		alert("你未选择任何照片,请选择后上传");
		return false;
	}

	var imgalignlist= new Array("","left","center","right");

	var imgalign;
	for(i=0;i<4;i++)
	{
		if(linkForm.spImgAlign1[i].checked)
		{
			imgalign = imgalignlist[i];
		}
	}
	window.parent.Ok();
	return true;
}

function geturl(url)
{	
	AddLink1(url);
}
function AddLink1(str1) 
{	
	var imgalignlist= new Array("","left","center","right");
	var imgalign;
	for(i=0;i<4;i++)
	{
		if(form1.spImgAlign[i].checked)
		{
			imgalign = imgalignlist[i];
			linkForm.spImgAlign1[i].checked = true;
			break;

		}
	}
	/*
	if(form1.spImgThumb[0].checked)
	{
		linkForm.spImgThumb1[0].checked = true;
		str1=str1.replace("pic","abpic");
	}else{
		linkForm.spImgThumb1[1].checked = true;
	}
	*/
	str1=domain+str1;
	linkForm.url.value = str1;

	window.parent.Ok();
	return true;
}
function locat()
{	
	chgdiv(0);
	showDiv("showing",0);
	alert(document.getElementById("sizeerr").innerHTML);
}
function error()
{
	chgdiv(0);
	showDiv("showing",0);
	alert(document.getElementById("fail").innerHTML);
}
//-->
</script>
<style type="text/css">
<!--
body,td,th {
	font-size: 12px;
}
-->
</style></head>
<body scroll="no" style="margin: 0px;OVERFLOW: hidden">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#E7E3C6" id="tabst">
<tr>
<td width="10">&nbsp;</td>
<td width="112" height="30" align="center" nowrap class="on" id="addsever" >添加网上图片</td>
<td width="106" id="addseverlink" align="center" class="off" nowrap style="display:none"><a href="#" onClick="chgdiv(1);return false;">添加网上图片</a></td>
<td width="1" bgcolor="#C6C78C">|</td>
<td width="112" height="30" align="center" nowrap class="on" id="addlocal" style="display:none">添加本机图片</td>
<td width="106" id="addlocallink" align="center" class="off" nowrap><a href="#" onClick="chgdiv(0);return false;">添加本机图片</a></td>
<td align="right">&nbsp;</td>
</tr>
</table>
<div id="imgaddsever">
<form name="linkForm" onSubmit="return AddLink(this);">
<table border="0" cellpadding="1" cellspacing="6" class="formhd">
<tr>
<td nowrap class="f14"><strong>网址：</strong><input type="text" name="url" id="url" style="width:290px" value="http://"></td>
</tr>
</table>
<table width="410" border="0" cellpadding="1" cellspacing="6" class="formhd">
<tr>
<td colspan="4" nowrap class="f14"><strong>图片位置</strong></td>
</tr>
<tr>
<td align="center" class="f14"><img src="fck_image/imgl1.gif" border="0"><br><input id="spImgAlign10" name="spImgAlign1" type="radio" value="0" checked="checked">默认</td>
<td align="center" class="f14"><img src="fck_image/imgl2.gif" border="0"><br><input id="spImgAlign11" name="spImgAlign1" type="radio" value="1">居左</td>

<td align="center" class="f14"><img src="fck_image/imgl3.gif" border="0"><br><input id="spImgAlign12" name="spImgAlign1" type="radio" value="2">居中</td>
<td align="center" class="f14"><img src="fck_image/imgl4.gif" border="0"><br><input id="spImgAlign13" name="spImgAlign1" type="radio" value="3">居右</td>
</tr>
<!--tr>
<td colspan="4" nowrap class="f14"><strong>图片显示</strong> :
 <input name="spImgThumb1" type="radio" value="" checked="checked">缩略图&nbsp; 
 <input name="spImgThumb1" type="radio" value="">原始大小</td>
</tr-->
<tr>
<td colspan="4" nowrap class="f14 formsb"><input name="tj" type="submit" value="插入图片"></td>
</tr></table>
</form>
</div>
<div id="imgaddlocal" style="display:none">

<form action="fck_image.php" method="post" name="form1" target="submitiframe" enctype="multipart/form-data" onSubmit="uping();return false;">
<input type="file" id="spPhotoFile0" name="spPhotoFile0" onChange="checkfile('spPhotoFile0');s('spPhotoFile0')">
<input type="hidden" name="action" value="add">
<script>
document.write("<input type='hidden' name='spRefURL' value='"+window.location.href+"'>");
if(document.all)
	document.write("<input type='hidden' name='BrowserType' id='BrowserType' value='1'>");
else
	document.write("<input type='hidden' name='BrowserType' id='BrowserType' value='2'>");
</script>
小于2M，JPG、GIF和PNG格式
<input type="hidden" name="spAlbumName" value="0">
<table width="410" border="0" cellpadding="1" cellspacing="6" class="formhd">
<tr>
<td colspan="4" nowrap class="f14"><strong>图片位置</strong></td>
</tr>
<tr>
<td align="center" class="f14"><img src="fck_image/imgl1.gif" border="0"><br><input id="spImgAlign4"  name="spImgAlign" type="radio" value="" checked="checked">默认</td>
<td align="center" class="f14"><img src="fck_image/imgl2.gif" border="0"><br><input id="spImgAlign3"  name="spImgAlign" type="radio" value="">居左</td>
<td align="center" class="f14"><img src="fck_image/imgl3.gif" border="0"><br><input id="spImgAlign2"  name="spImgAlign" type="radio" value="">居中</td>
<td align="center" class="f14"><img src="fck_image/imgl4.gif" border="0"><br><input id="spImgAlign1"  name="spImgAlign" type="radio" value="">居右</td>
</tr>
<tr>
<td colspan="4" nowrap class="f14"><strong>我的照片分类</strong> :
<?php 
	   @include_once($pre . $data.'picclass.php');
?>
	<select name="picclassid" id="picclassid">
	<option value="0">默认分类</option>
	<?php
	if ($variablepicclass)
	{
		foreach ($variablepicclass as $i => $rsClass)
		{
				if ($rsClass['picclass'])
				{ ?>
					<option value="<?php echo $rsClass['picclassid'];?>"<?php if ($rsClass['picclassid'] == $rs['picclassid']) { echo ' selected'; }?>><?php echo $rsClass['picclass'];?></option>
	<?php 		}
		}
	}
	?>
	</select>
 </td>
</tr>
<tr>
  <td colspan="4" nowrap class="f14"><strong>图片显示</strong>
    <input name="spImgThumb" type="radio" value="1">缩略图&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="spImgThumb" type="radio" value="0" checked="checked">原始大小</td></tr>	
<tr>
<td colspan="4" nowrap class="f14 formsb"><input name="tj" type="submit" value="插入图片" ></td>
</tr>
</table>
</form>
</div>
<div style="padding-top:15px;padding-left:10px;display:none" class="f14" id="showing">正在上传图片，请不要关闭此窗口！</div>
<div style="display:none" id="sizeerr">单张照片最大不得超过2M，您选择的一张或多张照片超过此限制，请检查后重新上传。</div>
<div style="display:none" id="fail">该图片未上传成功请重新上传</div>
<iframe name="submitiframe" src="about:blank" style="display:none"></iframe>
<script>document.getElementById("url").focus();</script>
</body></html>
